<script language="javascript" type="text/javascript">
	function hidden_calendar_div() {
		if ( $('has_expiration_date').checked ) {
			$('hidden_calendar_div').show();
		} else {
			$('hidden_calendar_div').hide();
			$('audio_asset_expiration_date').clear();
		}
	}
	
	function clear_fields() {
		$('audio_asset_file').clear();
		$('audio_asset_location').clear();
	}
	
	function upload() {
		clear_fields();
		$('tell_me_file_div').hide();
		$('upload_file_div').show();
	}
	
	function tell() {
		clear_fields();
		$('upload_file_div').hide();
		$('tell_me_file_div').show();
	}
	
	function show_authors() {
		$('all_authors_div').show();
	}
	
	Event.observe(window, 'load', function() {
		$('hidden_calendar_div').hide();
		$('upload_file_div').hide();
		$('tell_me_file_div').hide();
		$('all_authors_div').hide();
	});
</script>

<% @page_title = ' :: New Audio Asset' %>

<% content_for :sidebar do %>
	<div class="little_infos">
		<div class="little_content"><%= awareness_message %></div>
		<div class="little_content">
			<span class="sidebar_title">Info</span>
			The name inserted will be associated to audio asset's File and Metadata's File.<br />
			<b>E.g.:</b> Name: <i>lorem ipsum</i><br />
			File: <i>LoremIpsum.mp3</i><br />
			Metadata: <i>LoremIpsum.xml</i>
		</div>
	</div>
	
	<div class="little_infos">
	 	<div class="little_content">
			<span class="sidebar_title">Visit</span>
			<%= link_to 'Audio Assets<br />', :action => 'index' %>
			<%= view_programs %>
		</div>
	</div>
<% end %>

<h1>New Audio Asset</h1>
<% form_for :audio_asset, :url => { :action => 'create' }, 
	:html => { :multipart => true } do |f| %>
<% field_set_tag do %>
	<div class="span-7">
		<p><label for="audio_asset_name">Asset Name</label><br />
		<%= f.text_field :name, :class => 'text required_field' %><br /></p>
	</div>
	
	<div class="span-7 last">
		<p><label for="audio_asset_description">Description</label><br />
		<%= f.text_field :description, :class => 'text' %></p>
	</div>
	
	<hr class="separator" />
	<div class="span-7">
		<p><label for="audio_asset_format">Format</label><br />
		<%= f.select :format, @formats, { :prompt => 'Select a Format' } %></p>
	</div>
	
	<div class="span-7">
		<p><label for="audio_asset_genre">Genre</label><br />
		<%= f.select :genre, @genres.each {|g| g}, { :prompt => 'Select a Genre' } %></p>
	</div>
	
	<hr class="separator" />
	<div class="span-8 last">
		<p><%= check_box_tag :has_expiration_date, '1', false, :onclick => 'hidden_calendar_div()' %>
		<label for="has_expiration_date">This is a temporary Audio Asset</label><br />
		<div id="hidden_calendar_div" class="span-8">
			<p class="with_calendar_img"><label for="audio_asset_expiration_date">Expires in</label>
			<%= f.calendar_date_select :expiration_date, :popup => :force, :month_year => "label", :class => 'text' %></p>
		</div>
		</p>
	</div>
	
<% end %>

<% field_set_tag (link_to_function 'File', "Effect.toggle('file_div', 'appear', { duration: 0.5 }); return false;") do %>
	<div id="file_div">
	<div class="span-7">
		<p><%= radio_button_tag :essence, :upload, false, { :onclick => 'upload();' } %>
		<label for="essence_upload">Upload now</label></p>
	</div>
	
	<div class="span-7 last">
		<p><%= radio_button_tag :essence, :tell, false, { :onclick => 'tell();' } %>
		<label for="essence_tell">Where is Audio Asset?</label></p>
	</div>
	
	<div id="upload_file_div" class="span-17 last">
		<% field_set_tag 'Upload File' do %>
		<p><label for="file">File</label><br/>
		<%= f.file_field :file %></p>
		<% end %>
	</div>
	
	<div id="tell_me_file_div" class="span-17 last">
		<% field_set_tag 'Location of Audio Asset' do %>
		<p><label for="audio_asset_location">Location</label><br />
		<%= f.text_field :location, :class => 'text' %></p>
		<% end %>
	</div>
	</div>
<% end %>

<% field_set_tag (link_to_function 'Metadata File', "Effect.toggle('metadata_file_div', 'appear', {duration: 0.5}); return false;") do %>
	<div id="metadata_file_div">
	<div class="span-7">
		<p><label for="audio_asset_metadata_file">Metadata File</label>
		<%= f.file_field :metadata_file, :class => 'text' %></p>
	</div>
	</div>
<% end %>

<% field_set_tag (link_to_function 'Associate other Authors',
		"Effect.toggle('authors_div', 'appear', {duration: 0.5}); return false;") do %>
	<div id="authors_div" class="span-17 last">
		<p><%= radio_button_tag :associate, :authors, false, { :onclick => 'show_authors()' } %>
		<label for="associate_authors">Associate other Authors</label></p>
		
		<div id="all_authors_div" class="span-17 last">
		<%= render :partial => 'shared/authors', :locals => { :authors => @all_authors } %>
		</div>
	</div>
<% end %>

	<div class="span-17 centered last">
		<%= submit_tag 'Create Audio Asset', :disable_with => "Creating&hellip;", :class => 'buttons' %>
	</div>
<% end %>